
package org.come.until;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class NewAESForServerUtil {
    static String Instance = "AES/CBC/PKCS5Padding";
    //    public static String sKey = "XYXYBOBOBS505DGG";
    public static String sKey = "XYXYBOBOBS404DGG";
    static String AES = "AES";
    static String UTF_8 = "UTF-8";
    static String GB2312 = "GBK";
    static SecretKeySpec JMskeySpec;
    static IvParameterSpec JMiv;
    static SecretKeySpec skeySpec;
    static IvParameterSpec iv;

    static {
        byte[] raw;
        try {
            raw = sKey.getBytes();
            JMskeySpec = new SecretKeySpec(raw, "AES");
//            JMiv = new IvParameterSpec("YUAN030905060777".getBytes());
            JMiv = new IvParameterSpec("YUAN030908090777".getBytes());
        } catch (Exception var2) {
        }

        try {
            raw = sKey.getBytes("ASCII");
            skeySpec = new SecretKeySpec(raw, AES);
//            iv = new IvParameterSpec("YUAN030905060777".getBytes());
            iv = new IvParameterSpec("YUAN030908090777".getBytes());
        } catch (Exception var1) {
        }

    }

    public NewAESForServerUtil() {
    }

    public static String AESJDKEncode(String content) {
        try {
            byte[] encrypted = GZip.gZip(content.getBytes());
            Cipher Encode = Cipher.getInstance(Instance);
            Encode.init(1, JMskeySpec, JMiv);
            encrypted = Encode.doFinal(encrypted);
            return GsonUtil.getGsonUtil().getgson().toJson((new BASE64Encoder()).encode(encrypted)) + "\n";
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static String AESJDKDncode(String content) {
        try {
            content = (String)GsonUtil.getGsonUtil().getgson().fromJson(content, String.class);
            byte[] encrypted1 = (new BASE64Decoder()).decodeBuffer(content);
            Cipher Dncode = Cipher.getInstance(Instance);
            Dncode.init(2, skeySpec, iv);
            byte[] original = Dncode.doFinal(encrypted1);
            original = GZip.unGZip(original);
            String originalString = new String(original, UTF_8);
            return originalString;
        } catch (Exception var5) {
            var5.printStackTrace();
            return null;
        }
    }
}
